import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SolutionInterview17_17 {

    public static class Trie{
        List<Integer> end=new ArrayList<>();
        Trie[] children=new Trie[26];

        public void insert(String s,int t){
            Trie node=this;
            for (char c : s.toCharArray()) {
                if (node.children[c-'a']==null){
                    node.children[c-'a']=new Trie();
                }
                node=node.children[c-'a'];
                node.end.add(t);
            }
        }

        public int[] query(String s){
            Trie node=this;
            for (char c : s.toCharArray()) {
                if (node.children[c-'a']==null){
                    return new int[]{};
                }
                node=node.children[c-'a'];
            }
            int[] ans=new int[node.end.size()];
            for (int i=0;i<node.end.size();i++){
                ans[i]=node.end.get(i);
            }
            return ans;
        }
    }

    public int[][] multiSearch(String big, String[] smalls) {
        Trie trie=new Trie();
        for (int i=0;i<big.length();i++){
            trie.insert(big.substring(i),i);
        }
        int[][] ans=new int[smalls.length][];
        for (int i=0;i<ans.length;i++){
            ans[i]=trie.query(smalls[i]);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.deepToString(new SolutionInterview17_17().multiSearch("mississippi", new String[]{"is", "ppi", "hi", "sis", "i", "ssippi"})));
    }
}
